<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="参与方名称" prop="organizationName">
        <el-input
          v-model="queryParams.organizationName"
          placeholder="请输入参与方名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['contract:contractSigning:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="contractSigningList">
      <el-table-column label="合同编码" align="center" prop="contractId" min-width="180" show-overflow-tooltip/>
      <el-table-column label="参与方名称" align="center" prop="organizationName" min-width="180" show-overflow-tooltip/>
      <el-table-column label="签署状态" align="center" prop="contractSignStatus" width="100">
        <template slot-scope="{ row }">
          <el-tag v-if="row.contractSignStatus === 1" type="info">待签署</el-tag>
          <el-tag v-else-if="row.contractSignStatus === 3" type="danger">签署失败</el-tag>
          <el-tag v-else-if="row.contractSignStatus === 2">签署成功</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="签署类型" align="center" prop="signingType" width="100">
        <template slot-scope="{ row }">
          <span v-if="row.signingType === 1">接收方</span>
          <span v-else-if="row.signingType === 0">发起方</span>
        </template>
      </el-table-column>
      <el-table-column label="签署时间" align="center" prop="signTime" width="180" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-more-outline"
            @click="handleSign(scope.row)"
            v-if="scope.row.contractSignStatus === 1 && organizationId === scope.row.organizationId"
            v-hasPermi="['contract:contractInfo:sign']"
          >签署</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listSigningList, signContractSigning } from "@/api/contract/contractInfo"
import store from "@/store";

export default {
  name: "ContractSigning",
  props:{
    contractId:{
      type:String,
    },
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      // 显示搜索条件
      showSearch: true,
      organizationId:store.getters.organizationId,
      // 总条数
      total: 0,
      // 合同签署表格数据
      contractSigningList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        organizationId: null,
        contractId: null,
        organizationName: null,
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询合同签署列表 */
    getList() {
      this.loading = true
      listSigningList(this.queryParams).then(response => {
        this.contractSigningList = response.rows
        this.total = response.total
        this.loading = false
      })
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },

    handleSign(row){
      signContractSigning(row.signingId).then(response => {
        if (response.code === 200){
          window.open(response.data)
        }
      })
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('contract/contractSigning/export', {
        ...this.queryParams
      }, `contractSigning_${new Date().getTime()}.xlsx`)
    }
  },
  watch:{
    contractId:{
      handler(val){
        if (val){
          this.queryParams.contractId = val
        }
      },
      immediate:true
    }
  }
}
</script>
